package com.yin.myproject.core;

import com.yin.myproject.util.TaskKeyUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @author Eason
 * @create 2018-04-08 10:09
 **/
public class ScheduleTask {
    /**
     * 唯一标识
     */
    private String key;
    /**
     * 目标类，用于获取对象
     */
    private String targetClazz;
    /**
     * 目标对象名称
     */
    private String targetBean;
    /**
     * 目标方法
     */
    private String targetMethod;
    /**
     * cron表达式
     */
    private String cronExpression;
    /**
     * 开始时间
     */
    private Date startTime;
    /**
     * 周期（秒）
     */
    private long period;

    private String currentServer;
    /**
     * 参数
     */
    private Object[] params;
    /**
     * 类型
     */
    private String type;

    private int runTimes;

    private long lastRunningTime;

    public boolean begin(Date sysTime) {
        return null != sysTime && sysTime.after(startTime);
    }

    /**
     * @return the key
     */
    public String getKey() {
        if (!StringUtils.isEmpty(key)) {
            return key;
        } else {
            return TaskKeyUtil.buildKey(this);
        }
    }

    /**
     * @param key the key to set
     */
    public void setKey(String key) {
        this.key = key;
    }

    public String getTargetMethod() {
        return targetMethod;
    }

    public void setTargetMethod(String targetMethod) {
        this.targetMethod = targetMethod;
    }

    public String getCronExpression() {
        return cronExpression;
    }

    public void setCronExpression(String cronExpression) {
        this.cronExpression = cronExpression;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public long getPeriod() {
        return period;
    }

    /**
     * @param period 单位：毫秒ms
     */
    public void setPeriod(long period) {
        this.period = period;
    }

    public String getCurrentServer() {
        return currentServer;
    }

    public void setCurrentServer(String currentServer) {
        this.currentServer = currentServer;
    }

    public Object[] getParams() {
        return params;
    }

    public void setParams(Object... params) {
        this.params = params;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getRunTimes() {
        return runTimes;
    }

    public void setRunTimes(int runTimes) {
        this.runTimes = runTimes;
    }

    public long getLastRunningTime() {
        return lastRunningTime;
    }

    public void setLastRunningTime(long lastRunningTime) {
        this.lastRunningTime = lastRunningTime;
    }

    /**
     * @return the targetBean
     */
    public String getTargetBean() {
        return targetBean;
    }

    /**
     * @param targetBean the targetBean to set
     */
    public void setTargetBean(String targetBean) {
        this.targetBean = targetBean;
    }

    /**
     * @return the targetClazz
     */
    public String getTargetClazz() {
        return targetClazz;
    }

    public void setTargetClazz(String className) {
        this.targetClazz = className;
    }

    /**
     * @param targetClazz the targetClazz to set
     */
    public void setTargetClazz(Class<?> targetClazz) {
        this.targetClazz = targetClazz.getName();
    }
}
